﻿@{
    Layout = null;
    var plugName = @user.admin.cyt369.com.Areas.UserAdmin.Models.PlugName.Name;
    var tableName = PageViewModel.PageTableID(this);
    var tableToolBar = PageViewModel.PageTableToolbar(this);

    var editFunName = PageViewModel.PageFunctionName(this, "edit_app");
    var editDlgName = PageViewModel.PageEditDialog(this);
    var saveEditFunName = PageViewModel.PageFunctionName(this, "save_app");
    var deleteFunName = PageViewModel.PageFunctionName(this, "delete_app");
}

<div style="height:100%">
    <script type="text/javascript">
        function @editFunName (id) {
            var dlg = $dlg('@editDlgName');
            dlg.dialog({
                title: '系统应用', width: 900, height: 550,
                closed: false, cache: false, modal: true, maximizable: true, resizable: true, maximized: false,
                href: '~/@plugName/App/_EditAppDlg?ID=' + id,
                onResize: function () {
                    $(this).dialog('center');
                },
                buttons: [
                    {
                        text: "保 存",
                        handler: function () { @saveEditFunName (); },
                        iconCls: "icon-save"
                    }, {
                        text: "取 消",
                        handler: function () {
                            $("#@editDlgName").dialog("close");
                        },
                        iconCls: "icon-cancel"
                    }
                ],
                onLoad: function () {
                    LoadObject(id, "~/@plugName/App/GetAppByID/", function (item) {
                        if (item != null) {
                            var form = $("#@editDlgName").find("form");
                            form.form("load", item);
                            if (item.Enable) {
                                form.find("#Enable").switchbutton("check");
                            } else {
                                form.find("#Enable").switchbutton("uncheck");
                            }
                        }
                    });
                }
            });
        }

        function @saveEditFunName () {
            var form = $("#@editDlgName").find("form");
            if (form.form('enableValidation').form('validate')) {
                var item = form.form_to_json();
                var item = form.form_to_json(function (form, item) {
                    item.Enable = form.find("#Enable").switchbutton("options").checked;
                });
                $.ajax({
                    url: "~/@plugName/App/SaveApp",
                    type: "POST",
                    data: item,
                    success: function (e) {
                        if (e.Result) {
                            $.messager.alert('保存成功', '保存成功!', 'info', function () {
                                $('#@editDlgName').dialog('close');
                                $('#@tableName').datagrid('reload');
                            });
                        } else {
                            $.messager.alert('保存失败', '保存失败: ' + e.Msg, 'error');
                        }
                    },
                    error: function (e) {
                        ShowAjaxError(e);
                    }
                });
            }
        }

        function @deleteFunName (id) {
            if (id > 0 && confirm("确认删除系统信息?")) {
                $.ajax({
                    async: false,
                    method: "DELETE",
                    url: $.Content("~/@plugName/App/DeleteApp/" + id),
                    context: $("#@tableName"),
                    success: function (e) {
                        if (e.Result) {
                            this.datagrid('reload');
                        } else {
                            $.messager.alert('删除数据', '删除失败: ' + e.Msg, 'error');
                        }
                    },
                    error: function (e1, e2, e3) {
                        ShowAjaxError(e1, "删除数据");
                        this.datagrid('reload');
                    }
                });
            }
        }
    </script>

    <!-- -->
    <table id="@tableName" class="easyui-datagrid" style="width:100%" rownumbers="true" fitColumns="true" fit="true"
           pagination="true" pageSize="@SystemSettingService.Instance.PageSize" pageList="@SystemSettingService.Instance.PageList"
           data-options="striped:true,border:false,singleSelect:true,url:'~/@plugName/App/GetApps',method:'get',toolbar:'#@tableToolBar'">
        <thead>
            <tr>
                <th data-options="field:'_edit',align:'center',formatter:function(v,r,i){
                        return GridRowEditFmt('@editFunName', r.Id);
                    }" width="45"></th>
                <th data-options="field:'_remove',align:'center',formatter:function(v,r,i){
                        return GridRowDeleteFmt('@deleteFunName', r.Id);
                    }" width="45"></th>
                <th data-options="field:'Name',width:100">系统名称</th>
                <th data-options="field:'AppID',width:100,align:'center'">AppID</th>
                <th data-options="field:'AppKey',width:100">AppKey</th>
                <th data-options="field:'LogoutUrl',width:100">注销回调</th>
                <th data-options="field:'CreatedUserID',width:100,formatter:function(v,r,i){
                    var u = GetObject(v, '~/Systems/GetUserByID');
                    if(u != null&&u.User != null) { return u.User.FullName; }
                }">创建人</th>
                <th data-options="field:'CreatedTime',width:100,align:'center',formatter:$.DateTimeFmt">创建时间</th>
                <th data-options="field:'Description',width:100">备注</th>
            </tr>
        </thead>
    </table>
    <div id="@tableToolBar" class="easyui-panel table-toolbar">
        <a href="javascript:@editFunName ()" class="easyui-linkbutton t-btn"><i class="fa fa-plus-circle" style="color:green"></i><span>新增</span></a>
    </div>
</div>